//
//  MyInformation.swift
//  BirthdayManager
//
//  Created by Aaron_Chan on 2020/12/21.
//  Copyright © 2020 Charles. All rights reserved.
//

import Foundation
import UIKit

class MyInfo : NSObject, NSCoding {
    static let userPath =
        NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).first! + "myinformation.data"
    var name: String?
    var date: String?
    var avatar: UIImage?
    
    required init?(coder: NSCoder) {
        name=(coder.decodeObject(forKey: "nameKey") as? String)
        date=(coder.decodeObject(forKey: "dateKey") as? String)
        avatar=(coder.decodeObject(forKey: "avatarKey")as? UIImage)
    }
    
    func encode(with coder: NSCoder) {
        coder.encode(self.name,forKey: "nameKey")
        coder.encode(self.date,forKey: "dateKey")
        coder.encode(self.avatar,forKey: "avatarKey")
    }//告诉ios要保存什么对象，同时用什么方式保存
    
    init(name:String?,date:String?,avatar:UIImage?) {
        self.name=name
        self.date=date
        self.avatar=avatar
    }
}
